{% extends "base.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}
{% load static %}
{% load ietf_filters %}
{% load person_filters textfilters %}
{% block pagehead %}
    <link rel="alternate"
          type="application/atom+xml"
          href="/feed/group-changes/{{ group.acronym }}/">
{% endblock %}
{% block title %}{{ doc.title }}{% endblock %}
{% block content %}
    {% origin %}
    {{ top|safe }}
    {% include "doc/revisions_list.html" %}
    <div id="doc-timeline"></div>
    {% if doc.rev|charter_major_rev != latest_rev|charter_major_rev %}
        <div class="alert alert-warning my-3">
            The information below is for an older
            {% if doc.rev|charter_minor_rev %}
                proposed
            {% else %}
                approved
            {% endif %}
            charter
        </div>
    {% else %}
        {% if doc.rev != latest_rev %}
            {% if doc.rev|charter_minor_rev %}
                <div class="alert alert-warning my-3">
                    The information below is for an older version of the current proposed rechartering effort
                </div>
            {% else %}
                <div class="alert alert-warning my-3">
                    The information below is for the currently approved charter, but newer proposed charter text exists
                </div>
            {% endif %}
        {% else %}
            {% if doc.rev|charter_minor_rev and doc.rev|charter_major_rev != '00' %}
                <div class="alert alert-info my-3">
                    The information below is for a proposed recharter. The current approved charter is version {{ doc.rev|charter_major_rev }}
                </div>
            {% endif %}
        {% endif %}
    {% endif %}
    <table class="table table-sm table-borderless">
        <tbody class="meta border-top">
            <tr>
                <th scope="row">Document</th>
                <th scope="row">
                    {% if doc.get_state_slug != "approved" %}
                        Proposed charter
                    {% else %}
                        Charter
                    {% endif %}
                </th>
                <td class="edit"></td>
                <th scope="row">
                    {{ group.name }} {{ group.type.name }}
                    <a href="{{ group.about_url }}">({{ group.acronym }})</a>
                    {% if snapshot %}<span class="badge rounded-pill text-bg-warning">Snapshot</span>{% endif %}
                </th>
            </tr>
            <tr>
                <td></td>
                <th scope="row">Title</th>
                <td class="edit">
                    {% if not snapshot and can_manage %}
                        {% doc_edit_button 'ietf.doc.views_charter.change_title' name=doc.name %}
                    {% endif %}
                </td>
                <td>{{ doc.title }}</td>
            </tr>
            <tr>
                <td></td>
                <th scope="row">Last updated</th>
                <td class="edit"></td>
                <td>{{ doc.time|date:"Y-m-d" }}</td>
            </tr>
            <tr>
                <td></td>
                <th scope="row">
                    <a href="{% url 'ietf.doc.views_help.state_help' type='charter' %}">State</a>
                </th>
                <td class="edit">
                    {% if not snapshot and can_manage %}
                        {% doc_edit_button 'ietf.doc.views_charter.change_state' name=doc.name %}
                    {% endif %}
                </td>
                <td>
                    {% if doc.get_state %}
                        <span title="{{ doc.get_state.desc }}" class="{% if doc.get_state.name|slugify == 'approved' %}text-success{% endif %}">{{ doc.get_state.name }}</span>
                    {% else %}
                        No document state
                    {% endif %}
                    {% if chartering == "initial" %}<span class="badge rounded-pill text-bg-info">Initial chartering</span>{% endif %}
                    {% if chartering == "rechartering" %}<span class="badge rounded-pill text-bg-info">Rechartering</span>{% endif %}
                </td>
            </tr>
        </tbody>
        <tbody class="meta border-top">
            <tr>
                <th scope="row">{{ group.type.name }}</th>
                <th scope="row">State</th>
                <td class="edit"></td>
                <td>
                    <span class="{% if group.state.name|slugify == 'active' %}text-success{% endif %}">
                        {{ group.state.name }}
                    </span>
                </td>
            </tr>
        </tbody>
        <tbody class="meta border-top">
            {% if group.type_id != "rg" %}
                <tr>
                    <th scope="row">IESG</th>
                    <th scope="row">Responsible AD</th>
                    <td>
                    </td>
                    <td>
                        {% person_link group.ad_role.person %}
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                    </th>
                    <th scope="row">
                        Charter edit AD
                    </th>
                    <td class="edit">
                        {% if can_manage %}
                            {% doc_edit_button 'ietf.doc.views_charter.edit_ad' name=doc.name %}
                        {% endif %}
                    </td>
                    <td>
                        {% person_link doc.ad %}
                    </td>
                </tr>
            {% endif %}
            {% if not snapshot and chartering %}
                <tr>
                    <td>
                    </td>
                    <th scope="row">
                        Telechat date
                    </th>
                    <td class="edit">
                        {% if can_manage %}
                            {% doc_edit_button 'ietf.doc.views_doc.telechat_date;charter' name=doc.name %}
                        {% endif %}
                    </td>
                    <td>
                        {% if not telechat %}
                            <span class="text-body-secondary">(None)</span>
                        {% else %}
                            On agenda of {{ telechat.telechat_date|date:"Y-m-d" }} IESG telechat
                        {% endif %}
                        {% if ballot_summary %}
                            <br>
                            <i>{{ ballot_summary }}</i>
                        {% endif %}
                    </td>
                </tr>
            {% endif %}
            <tr>
                <td>
                </td>
                <th scope="row">
                    Send notices to
                </th>
                <td class="edit">
                    {% if can_manage %}
                        {% doc_edit_button 'ietf.doc.views_doc.edit_notify;charter' name=doc.name %}
                    {% endif %}
                </td>
                <td>
                    {{ doc.notify|default:'<span class="text-body-secondary">(None)</span>' }}
                </td>
            </tr>
        </tbody>
    </table>
    <p class="buttonlist">
        {% if not snapshot and can_manage %}
            {% if chartering %}
                {% url 'ietf.doc.views_charter.change_state' name=doc.name option='abandon' as abandon_url %}
                {% if abandon_url %}
                    <a class="btn btn-danger" href="{{ abandon_url }}">
                        Abandon chartering
                    </a>
                {% endif %}
                {% if user|has_role:"Secretariat" %}
                    {% url 'ietf.doc.views_charter.approve' name=doc.name as approve_url %}
                    {% if approve_url %}
                        <a class="btn btn-primary" href="{{ approve_url }}">
                            Approve charter
                        </a>
                    {% endif %}
                {% endif %}
            {% else %}
                {% if group.state_id == "proposed" or group.state_id == "bof" %}
                    {% url 'ietf.doc.views_charter.submit' name=doc.name option='initcharter' as start_url %}
                    {% if start_url %}
                        <a class="btn btn-primary" href="{{ start_url }}">
                            Start chartering
                        </a>
                    {% endif %}
                {% else %}
                    {% url 'ietf.doc.views_charter.submit' name=doc.name option='recharter' as recharter_url %}
                    {% if recharter_url %}
                        <a class="btn btn-primary" href="{{ recharter_url }}">
                            Recharter
                        </a>
                    {% endif %}
                {% endif %}
            {% endif %}
        {% endif %}
    </p>
    {% if not snapshot and can_manage and chartering and group.state_id != "conclude" %}
        <p>
            <a class="btn btn-primary"
               href="{% url 'ietf.doc.views_charter.submit' name=doc.name %}">
                Change charter text
            </a>
        </p>
    {% endif %}
    {% if doc.rev != "" %}
        <div class="card mt-5">
            <div class="card-header">
                {{ doc.name }}-{{ doc.rev }}
            </div>
            <div class="card-body">
                {{ content }}
            </div>
        </div>
    {% endif %}
    {% if not snapshot and chartering %}
        <h2 class="my-3">
            Proposed milestones
        </h2>
        {% if can_manage %}
            <p>
                <a class="btn btn-primary"
                   href="{% url 'ietf.group.milestones.edit_milestones;charter' group_type=doc.group.type_id acronym=doc.group.acronym %}">
                    Edit milestones
                </a>
            </p>
        {% endif %}
        {% if milestones %}
            {% include "group/milestones.html" with heading=True %}
        {% else %}
            <p>
                No milestones for charter found.
            </p>
        {% endif %}
    {% endif %}
{% endblock %}
{% block js %}
    <script src="{% static 'ietf/js/d3.js' %}">
    </script>
    <script src="{% static 'ietf/js/document_timeline.js' %}">
    </script>
{% endblock %}